package com.hly.dao;

import com.hly.model.Items;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface IitemsDao {

    @Insert("insert items (price,amount,order_id,good_id) value (#{price},#{amount},#{orderId},#{goodId})")
    @SelectKey(keyProperty = "id" , statement = "SELECT LAST_INSERT_ID()", before = false, resultType = Integer.class)
    public boolean insertItems(Items items);

    @Select("select * from items where order_id = #{id} ")
    @Results({
            @Result(id = true , property = "id" , column = "id"),
            @Result(property = "price" , column = "price"),
            @Result(property = "amount" , column = "amount"),
            @Result(property = "orderId" , column = "order_id"),
            @Result(property = "goodId" , column = "good_id"),
            @Result(property = "good" , column = "good_id" ,
            one = @One(select = "com.hly.dao.IGoodsDao.selectById",fetchType = FetchType.EAGER)
            )
    })
    public Items selectByOrderId(@Param("id") Integer orderId);

}
